<template>
	<view class="page_con">
		<view 
			class="list_con"
			style="flex: 1;">
			<view class="yaofang_area"
				v-for="(yaofang, yaofang_index) in yaofang.list" 
				:key="yaofang.list_key"
				@click="goto_yaofang_page(yaofang.id)"
				>
				{{yaofang.name}}
			</view>
		</view>
		<view class="btn_con">
			<view class="btn" @click="goto_yaofang_page(0)">添加药方</view>
		</view>
	</view>
</template>
<script>
	import { get_yaofang_list } from '@/util/api/api.js';
	
	export default {
		data() {
			return {
				url: "/index.php/html5/yaofang/get_yaofang_list",
				tablist:{
					list:[
						{
							name:'诊断列表'
						},
						{
							name:'医生列表'
						},
						{
							name:'订单列表'
						},
						{
							name:'患者列表'
						},
						{
							name:'药方列表'
						}
					],
					current:0
				},
				yaofang:{
					list:[],
					list_key:0,
					curpage:0,
					listnum:20,
					total:0
				},
				tab:{
					list:[],
					current:1
				}
			}
		},
		onLoad() {
			this.tab.list = getApp().globalData.admin_tab_list
			this.get_yaofang_list()
		},
		onReachBottom() {
			console.log('已经到底了')
			// console.log(this.listQuery.curpage)
			// this.get_yaofang_list(0,0);
			if (this.yaofang.curpage*this.yaofang.listnum >= this.total) {
				this.finished = '已经到底了'; //已经滑到底的提醒
				return false;
			}else{
				this.get_yaofang_list(this.yaofang.curpage,this.yaofang.listnum);
			}
		},
		methods: {
			goto_yaofang_page(id=0){
				uni.navigateTo({
					url: '../yaofang/yaofang?id='+id
				});
			},
			get_yaofang_list(curpage=0,listnum=0){
				let that = this
				let data = {
					curpage:curpage,
					listnum:listnum
				}
				
				get_yaofang_list(data).then((res)=>{
					if (res.code==200) {
						that.yaofang.list.push(...res.data.datalist)
						that.yaofang.curpage = res.data.pages
						that.yaofang.curpage = res.data.total
					} else{
						// that.showToast(res.message)
					}
				})
			},
			showToast(text) {
				this.$refs.uToast.show({
					title: text,
					// url: '/pages/user/index'
				})
			},
		}
	}
</script>
<style>
.page_con{
	width: 100%;
	height: 100vh;
	background-color: #F5F5F5;
	display: flex;
	flex-direction: column;
}
.list_con{
	overflow-y: scroll;
}
.yaofang_area{
	width: 700rpx;
	height: 100rpx;
	line-height: 50rpx;
	margin: 25rpx;
	padding: 25rpx;
	background-color: #fff;
}

.btn_con{
	width: 100%;
	height: 150rpx;
}
.btn{
	width: 690rpx;
	height: 88rpx;
	background: #15BBA2;
	border-radius: 44rpx;
	line-height: 88rpx;
	font-size: 36rpx;
	font-family: PingFang SC;
	font-weight: bold;
	color: #FFFFFF;
	text-align: center;
	margin: 30rpx;
}
</style>
